/**
 * 	write on 2005-10-26 11:49:25.
 */
package org.nanhill.xmlro;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Xmlro input / output transport, used for specified xmlro client (e.g
 * sro/gsp...).
 * 
 * @author alin
 * 
 */
public interface XmlroTransport {
	void setSerializerFactory(SerializerFactory serializerFactory);

	/**
	 * Get transport character set.
	 * 
	 * @return
	 */
	String getCharacterSet();

	/**
	 * Set transport character set.
	 * 
	 * @param charSet
	 */
	void setCharacterSet(String charSet);

	/**
	 * Receive generic object through input stream.
	 * 
	 * @param inputStream
	 * @return
	 * @throws XmlroException
	 * @throws IOException 
	 */
	Object receive(InputStream inputStream) throws XmlroException, IOException;

	/**
	 * Receive wrap object through input stream.
	 * 
	 * @param <E>
	 * @param wrap
	 * @param inputStream
	 * @return
	 * @throws XmlroException
	 * @throws IOException 
	 */
	<E> E receive(E wrap, InputStream inputStream) throws XmlroException, IOException;

	/**
	 * Receive generic object through xml.
	 * 
	 * @param xml
	 * @return
	 * @throws XmlroException
	 */
	Object receive(String xml) throws XmlroException;

	/**
	 * Receive wrap object through xml.
	 * 
	 * @param <E>
	 * @param wrap
	 * @param xml
	 * @return
	 * @throws XmlroException
	 */
	<E> E receive(E wrap, String xml) throws XmlroException;

	/**
	 * Receive the instance of wrap class through xml.
	 * 
	 * @param <E>
	 * @param wrapClz
	 * @param xml
	 * @return
	 * @throws XmlroException
	 */
	<E> E receive(Class<E> wrapClz, String xml) throws XmlroException;

	/**
	 * Receive the instance of wrap class through input stream.
	 * 
	 * @param <E>
	 * @param wrapClz
	 * @param inputStream
	 * @return
	 * @throws XmlroException
	 * @throws IOException 
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 */
	<E> E receive(Class<E> wrapClz, InputStream inputStream)
			throws XmlroException, IOException;

	/**
	 * Translate input object to xml.
	 * 
	 * @param in
	 * @return
	 * @throws XmlroException
	 */
	String send(Object in) throws XmlroException;

	/**
	 * Send object to ouput stream.
	 * 
	 * @param in
	 * @param outputStream
	 * @throws XmlroException
	 * @throws IOException 
	 */
	void send(Object in, OutputStream outputStream) throws XmlroException, IOException;

}
